package com.yfore.jfinal.pdf.plugin;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;

import org.apache.commons.lang3.StringUtils;

public class MockServletOutputStream extends ServletOutputStream {

    private ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    @Override
    public boolean isReady() {
        return true;
    }

    @Override
    public void setWriteListener(WriteListener writeListener) {
        
    }

    @Override
    public void write(int b) throws IOException {
        outputStream.write(b);
    }

    public byte[] toByteArray(){
        return outputStream.toByteArray();
    }

    public String toString(){
        return StringUtils.toEncodedString(outputStream.toByteArray(), Charset.forName("UTF-8"));
    }
}
